var app = getApp();
Page({
    data:{
        page : {
            isend : false,
            doing : false,
            doo : 'jizi',
            pdata : {
                op : 'list',
                page : 1,
                status : 1,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        tabList : [{key:1,name:'进行中的'},{key:2,name:'已结束的'},{key:3,name:'我参与的'}],
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
		var zfid = options.zfid ? options.zfid : '';
		var shopid = options.shopid ? options.shopid : '';
        
        self.setData({
            'page.pdata.status' : options.status ? options.status : 1,
            'page.pdata.shopid' : shopid,
            'page.pdata.zfid' : zfid,
        });
        app.com.getLocation(self,function(loc){
            self.setData({
                'page.pdata.lat' : loc.latitude,
                'page.pdata.lng' : loc.longitude,
            });
            app.com.auth(function(user){
                app.com.getPage(self,self.data.page,20,function(res){
                    var data = res.data.data;
                    self.setData({
                       datalist : data.list,
                       Pagetheme : res.data.data.params.style,
                    },function(){
                        self.setData({
                            inited : true,
                        });
                    });

                    wx.setNavigationBarTitle({
                      title:  res.data.data.params.title ? res.data.data.params.title : '集字活动',
                    });

                },false,function(res){
                    app.com.alert(res.data.message);
                });
				app.com.setBar(app,self,shopid);
            });
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.article.title,
            path: '',
            imageUrl : self.data.article.img,
        }
    },
    tabChange(e){
        var self = this;

        if( self.data.ising || ( e.currentTarget.dataset.status == self.data.page.pdata.status ) ) return false;
        self.data.ising = true;

        self.setData({
            datalist : [],
            'page.pdata.status' : e.currentTarget.dataset.status,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
            wx.pageScrollTo({
                scrollTop: 0
            });
        });

        self.data.ising = false;
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})